import instance from './index';
import qs from 'qs';

const preUrlPath = '';
//获取用户组列表
const request = {
  p: ['api:group:fetch'],
  r: params => {
    return instance.get(`/group/fetchGroupList`, {params})
  }
};
//添加用户组
const add = {
  p: ['api:group:new'],
  r: params => {
    return instance.post(`/group/new`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//获取用户组信息
const info = {
  p: ['api:group:fetch'],
  r: params => {
    return instance.get(`/group/info`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//编辑用户组
const modify = {
  p: ['api:group:modify'],
  r: params => {
    return instance.post(`/group/modify`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//删除用户组
const remove = {
  p: ['api:group:delete'],
  r: params => {
    // return instance.get(`${preUrlPath}/group/${params.id}`)
    return instance.delete(`/group/del/${params.id}`)

  }
};
//获取用户信息
const userinfo = {
  p: ['api:group:fetch'],
  r: params => {
    return instance.get(`/user/info`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//关联组-用户关联组
const releGroup = {
  p: ['api:user:addGroupRlt'],
  r: params => {
    return instance.post(`/user/addGroupRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联组-角色关联组
const releGroupRole = {
  p: ['api:role:addGroupRlt'],
  r: params => {
    return instance.post(`/role/addGroupRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联用户-组关联
const releUserGroup = {
  p: ['api:group:addUserRlt'] 
};
//关联角色--用户组
const releroleGroup = {
  p: ['api:group:addRoleRlt']
};
//越权请求
const notAllowed = {
  p: ['get,/groups/notAllowed'],
  r: params => {
    return instance.get(`${preUrlPath}/GET/groups/notAllowed`, {params})
  }
}

export {
  request,
  remove,
  notAllowed,
  add,
  modify,
  info,
  userinfo,
  releGroup,
  releGroupRole,
  releUserGroup,
  releroleGroup
}
